package com.chengdu.third.controller;


import com.chengdu.third.dao.IBasicDao;
import com.chengdu.third.dao.ILawsDao;
import com.chengdu.third.dao.IZwxxDao;
import com.chengdu.third.pojo.Basic;
import com.chengdu.third.pojo.Laws;
import com.chengdu.third.pojo.User;
import com.chengdu.third.pojo.Zwxx;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;


@Controller
public class JumpController {


    @Autowired
    private ILawsDao iLawsDao;

    @Autowired
    private IZwxxDao iZwxxDao;

    @Autowired
    private IBasicDao iBasicDao;

    @GetMapping("/")
    public String indexPage(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum,
                            Model model){
        PageHelper.startPage(pagenum, 5);
        List<Laws> selectshixian = iLawsDao.selectshixian();

        List<Laws> selectxiangzheng = iLawsDao.selectxiangzheng();
        List<Laws> selectcun = iLawsDao.selectcun();

        PageInfo<Laws> pageInfo = new PageInfo<>(selectshixian);
        PageInfo<Laws> xiang = new PageInfo<>(selectxiangzheng);
        PageInfo<Laws> cun = new PageInfo<>(selectcun);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("xiang", xiang);
        model.addAttribute("cun", cun);

        return "index";
    }
    @GetMapping("/index")
    public String indexPag(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum,
                           Model model){
        PageHelper.startPage(pagenum, 5);
        List<Laws> selectshixian = iLawsDao.selectshixian();

        List<Laws> selectxiangzheng = iLawsDao.selectxiangzheng();
        List<Laws> selectcun = iLawsDao.selectcun();

        PageInfo<Laws> pageInfo = new PageInfo<>(selectshixian);
        PageInfo<Laws> xiang = new PageInfo<>(selectxiangzheng);
        PageInfo<Laws> cun = new PageInfo<>(selectcun);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("xiang", xiang);
        model.addAttribute("cun", cun);

        return "index";
    }

    //跳转到政策页面
    @GetMapping("/zhengce")
    public String  zhengce(){
        return "zhengce";
    }

    //跳转到基层页面
    @GetMapping("/jiceng")
    public String jiceng1(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum,
                          Model model){

        PageHelper.startPage(pagenum, 12);
        List<Basic> basics = iBasicDao.find();
        PageInfo<Basic> basicaa = new PageInfo<>(basics);
        model.addAttribute("pageInfo", basicaa);
        return "jiceng";
    }

    //跳转到便民服务页面
    @GetMapping("/bianmin")
    public String bianmin1(){
        return  "bianmin";
    }

    /**
     * 沟通互助
     * @return
     */
    @GetMapping("/goutong")
    public String communicatePage(Model model) {
        model.addAttribute("zwxx", new Zwxx());
        return "goutong";
    }

    @PostMapping("/zhongjian/goutong")
    public String commun(@RequestParam String letter_writer,@RequestParam String phonenumber,
                         @RequestParam String address,@RequestParam String receiving_AREA,
                         @RequestParam String  letter){
        iZwxxDao.addbufen(letter_writer, phonenumber, address, receiving_AREA, letter);

        return "redirect:/goutong";
    }

    /**
     * 监督管理
     * @return
     */
    @GetMapping("/jiandu")
    public String jianduPage() {
        return "jiandu";
    }

    /**
     * 服务发展
     * @return
     */
    @GetMapping("/fuwu")
    public String fuwuPage() {
        return "fuwu";
    }



    @GetMapping("/index1")
    public String index1(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum,
                         Model model){
        PageHelper.startPage(pagenum, 5);
        List<Laws> selectshixian = iLawsDao.selectshixian();

        List<Laws> selectxiangzheng = iLawsDao.selectxiangzheng();
        List<Laws> selectcun = iLawsDao.selectcun();

        PageInfo<Laws> pageInfo = new PageInfo<>(selectshixian);
        PageInfo<Laws> xiang = new PageInfo<>(selectxiangzheng);
        PageInfo<Laws> cun = new PageInfo<>(selectcun);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("xiang", xiang);
        model.addAttribute("cun", cun);

        return "index1";
    }

    @GetMapping("/HJ")
    public String hjpage(){
        return "HJ";
    }

    @GetMapping("/ZCJD")
    public String zcjd(){
        return "ZCJD";
    }


    @GetMapping("/NY")
    public String NYpage(){
        return "NY";
    }

    @GetMapping("/SB")
    public String SBpage(){
        return "SB";
    }
    @GetMapping("/YB")
    public String YBpage(){
        return "YB";
    }

    @GetMapping("/JY")
    public String JYpage(){
        return "JY";
    }

    @GetMapping("/HJ1")
    public String HJpage(){
        return "HJ";
    }

    @GetMapping("/SF")
    public String SFpage(){
        return "SF";
    }

    @GetMapping("/JT")
    public String JTpage(){
        return "JT";
    }

    @GetMapping("/ZF")
    public String ZFpage(){
        return "ZF";
    }
    @GetMapping("/JiaoY")
    public String JiaoYpage(){
        return "JiaoY";
    }

    @GetMapping("/QT")
    public String QTpage(){
        return "QT";
    }





}
